package com.zimin.cloud.gateway.controller;

import com.zimin.redis.constant.authorize.AuthorizeRedisConstant;
import com.zimin.redis.utils.RedisOperator;
import com.zimin.shared.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zimin
 * @since 2022/3/28 5:02 下午
 */
@RestController
@RequestMapping("/sys")
public class SystemAccountController {

    @Autowired
    private RedisOperator redisOperator;

    /**
     * <p>注销</p>
     *
     * @param userId 用户ID
     * @param token  用户token
     * @return com.zimin.shared.pojo.Result
     * @since 2022-03-28 17:06:48
     */
    @GetMapping("/logout/{userId}/{token}")
    public Result logout(@PathVariable(name = "userId") String userId,
                         @PathVariable(name = "token") String token) {
        redisOperator.del(String.format(AuthorizeRedisConstant.REDIS_LOGIN_INFO, token));
        redisOperator.del(String.format(AuthorizeRedisConstant.REDIS_LOGIN_ROLE, token));
        redisOperator.del(String.format(AuthorizeRedisConstant.REDIS_LOGIN_PERMISSIONS, token));
        redisOperator.del(String.format(AuthorizeRedisConstant.REDIS_LOGIN_TOKEN, userId));
        return Result.ok();
    }

}
